<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="关键字" prop="keyword">
        <el-input
          size="mini"
          v-model="queryParams.keyword"
          placeholder="请输入问题关键字"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          format="yyyy-MM-dd"
          value-format="timestamp"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
          size="mini"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" type="index" align="center" min-width="5%"/>
      <el-table-column label="姓氏" align="center" prop="lastName" key="lastName"/>
      <el-table-column label="名字" align="center" prop="firstName" key="firstName"/>
      <el-table-column label="邮箱" align="center" prop="email" key="email"/>
      <el-table-column label="国籍" align="center" prop="country" key="country"/>
      <el-table-column label="手机区号" align="center" prop="phoneAreaCode" key="phoneAreaCode"/>
      <el-table-column label="手机号" align="center" prop="phone" key="phone"/>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditStatus" key="auditStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.kyc_audit_status" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="auditUserName" key="auditUserName"/>
      <el-table-column label="审核时间" align="center" prop="auditTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.auditStatus === '0'"
            size="mini"
            type="text"
            @click="handleEdit(scope.row,'1')"
            v-hasPermi="['system:kycApply:edit']"
          >通过</el-button>
          <el-button
            v-if="scope.row.auditStatus === '0'"
            size="mini"
            type="text"
            @click="handleEdit(scope.row,'2')"
            v-hasPermi="['system:kycApply:edit']"
          >驳回</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleInfo(scope.row)"
            v-hasPermi="['system:kycApply:query']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="kyc验证详情" :visible.sync="detailOpen" width="50%" append-to-body>
      <el-form ref="form" :model="detail" label-width="100px">
        <el-row :gutter="24">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="姓氏: ">
                {{ detail.lastName }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="名字: ">
                {{ detail.firstName }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="邮箱: ">
                {{detail.email }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="手机区号: ">
                {{ detail.phoneAreaCode }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="手机号: ">
                {{detail.phone }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="国家: ">
                {{ detail.country }}
                <span v-if="detail.nationalityCountryCode">({{ detail.nationalityCountryCode }})</span>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="城市: ">
                {{detail.city }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="出生日期: ">
                {{detail.dateOfBirth }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="证件类型: ">
                {{detail.certType === 'id_card' ? '身份证': detail.certType === 'passport' ? '护照':'暂无'}}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12" v-if="detail.certType === 'id_card'">
            <div class="grid-content bg-purple">
              <el-form-item label="身份证正面: ">
                <span v-if="detail.portraitImg === null || detail.portraitImg === ''">暂无</span>
                <div class="viewer-list-img" v-else>
                  <viewer :images="detail.portraitImg">
                    <image-preview :src="detail.portraitImg" :key="detail.portraitImg" class="detail-img"/>
                  </viewer>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12" v-if="detail.certType === 'id_card'">
            <div class="grid-content bg-purple">
              <el-form-item label="身份证反面: ">
                <span v-if="detail.reverseSideImg === null || detail.reverseSideImg === ''">暂无</span>
                <div class="viewer-list-img" v-else>
                  <viewer :images="detail.reverseSideImg">
                    <image-preview :src="detail.reverseSideImg" :key="detail.reverseSideImg" class="detail-img"/>
                  </viewer>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12" v-if="detail.certType === 'passport'">
            <div class="grid-content bg-purple">
              <el-form-item label="护照首页: ">
                <span v-if="detail.portraitImg === null || detail.portraitImg === ''">暂无</span>
                <div class="viewer-list-img" v-else>
                  <viewer :images="detail.portraitImg">
                    <image-preview :src="detail.portraitImg" :key="detail.portraitImg" class="detail-img"/>
                  </viewer>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="账单地址(国家码): ">
                {{ detail.residentialCountryCode }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="账单地址(州/省): ">
                {{ detail.residentialState }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="账单地址(城市): ">
                {{ detail.residentialCity }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="账单地址(详情地址): ">
                {{ detail.residentialAddress }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="账单地址(邮编): ">
                {{ detail.residentialPostalCode }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="创建时间: ">
                {{ parseTime(detail.createTime) }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="审核人: ">
                {{detail.auditUserName }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="审核时间: ">
                {{ parseTime(detail.auditTime) }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="审核状态: ">
                <dict-tag :options="dict.type.kyc_audit_status" :value="detail.auditStatus"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="24" v-if="detail.auditStatus === '2'">
            <div class="grid-content bg-purple">
              <el-form-item label="驳回理由: ">
                {{detail.failRemark }}
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="detailOpen = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { applyPageList,getInfo,audit } from '@/api/triones/kycVerify'
export default {
  name: "index",
  dicts: ['kyc_audit_status'],
  data() {
    return {
      loading: false,
      showSearch: true,
      // 日期范围
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        auditStatus: '0',
        keyword: undefined
      },
      dataList: [],
      total: 0,
      detailOpen: false,
      detail:{}
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList () {
      this.loading = true;
      this.addDateRange(this.queryParams, this.dateRange);
      applyPageList(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 检索 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置 */
    resetQuery() {
      this.dateRange = [];
      this.auditDateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询详情 */
    handleInfo(row) {
      const id = row.id;
      getInfo(id).then(response => {
        this.detail = response.data;
        this.detail.certificateImg = response.data.certificateImg ? response.data.certificateImg.split(',') : [];
        this.detailOpen = true;
      })
    },
    /** kyc验证审核 */
    handleEdit(row, status) {
      if (status === '2') {
        this.reject(row);
      } else {
        const data = {
          id: row.id,
          auditStatus: status
        }
        this.$modal.confirm('是否确认邮箱为"' + row.email + '"的kyc信息数据审核通过？').then(() => {
          this.loading = true;
          return audit(data);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("审核成功！");
        }).finally(() => {
          this.loading = false;
        });
      }
    },
    /** 驳回 */
    reject(row) {
      const data = {
        id: row.id,
        auditStatus: '2',
        failRemark: ''
      }
      this.$prompt('请输入驳回原因', '驳回申请', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        data.failRemark = value;
        audit(data).then(response => {
          this.$message("操作成功");
          this.getList();
        })
      })
    }
  }
}
</script>
<style scoped lang="scss">

</style>
